/**
 * 2011-11-17下午1:16:30
 */
package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import util.MysqlConn;
import bean.Goods;

/**
 * @author Baicai 查询结果的类，在list界面显示
 */
public class ListGoods {

	/**
	 * 从数据库获取数据
	 * 
	 * @return List<Goods>
	 */
	public static List<Goods> getListGoods(String string) {
		List<Goods> list = new ArrayList<Goods>();
		try {
			ResultSet resultSet;
			MysqlConn.setSqlString(string);// 查询需要的信息
			resultSet = MysqlConn.queryDB();// 以resultSet获取查询结果
			while (resultSet.next()) {
				Goods goods = new Goods();// 以Goods对象获取结果集中得查询结果
				goods.setGoodsId(Integer.parseInt(resultSet
						.getString("goods_id")));
				goods.setGoodsState(Integer.parseInt(resultSet
						.getString("goods_state")));
				goods.setGoodsName(resultSet.getString("goods_name"));
				goods.setGoodsSort(resultSet.getString("goods_sort"));
				goods.setGoodsPrice(Float.valueOf(resultSet
						.getString("goods_price")));
				goods.setGoodsInformation(resultSet
						.getString("goods_information"));

				list.add(goods);// 将goods放入list
			}
			return list;// 返回得到的list
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MysqlConn.free();
		}
		return null;
	}
}
